package com.iflytek.shiro;

import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//Shiro配置类
@Configuration
public class ShiroConfig {

	//指定Shiro认证和授权时使用的Realm
	@Bean
	public Realm realm() {
	    UserRealm userRealm = new UserRealm();
	    //设置加密器
	    HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
	    credentialsMatcher.setHashAlgorithmName("md5");
	    credentialsMatcher.setHashIterations(3);  //散列3次
	    //userRealm.setCredentialsMatcher(credentialsMatcher);
	    return userRealm;
	}

	
	  //配置Shiro拦截器
	  
	  @Bean public ShiroFilterChainDefinition shiroFilterChainDefinition() {
	  DefaultShiroFilterChainDefinition chain = new
	  DefaultShiroFilterChainDefinition();
	  chain.addPathDefinition("/logout","logout"); //logout指定注销的路径
	  chain.addPathDefinition("/favicon.ico","anon"); //anon表示可以匿名访问，无需登录
	  chain.addPathDefinition("/css/**","anon");
	  chain.addPathDefinition("/login/**","anon");
	  chain.addPathDefinition("/lib/**","anon");
	  chain.addPathDefinition("/images/**","anon");
	  chain.addPathDefinition("/js/**","anon");
	  chain.addPathDefinition("/layui/**","anon");
	  chain.addPathDefinition("/**","authc"); //authc表示该路径需要认证才能访问 return chain; }
	  
	  return chain;
	  }
}
